{% extends 'front/user_base.html' %}
{% block css %}
    <link rel="stylesheet"
          href="{{ url_for('static', filename='css/pure-min.css') }}">
    <link rel="stylesheet"
          href="{{ url_for('static', filename='css/create.css') }}">
{% endblock %}
</head>
{% block content %}

<div class="content">
    <div class="header">
        <h2>修改密码</h2>
    </div>
    <div class="pure-g">
        {% for category, message in get_flashed_messages(with_categories=true) %}
            <div class="alert alert-{{ category }} alert-dismissable pure-u-1 pure-u-md-21-24">
                {{ message }}
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            </div>
        {% endfor %}
        <form class="pure-form pure-form-aligned pure-u-1 pure-u-md-21-24" action="{{ url_for('main.update_pwd') }}" method="post" onsubmit="return checkPost()">
            <fieldset>
                {{ form.csrf_token }}
                <div class="pure-control-group">
                    <label for="password" class="pure-u-1-3">密码</label>
                    {{ form.password(class='pure-u-2-3', id="password",placeholder="输入密码", required='') }}
                </div>
                <div class="pure-control-group">
                    <label for="password" class="pure-u-1-3">密码</label>
                    {{ form.repassword(class='pure-u-2-3', id="repassword",placeholder="确认密码", required='') }}
                </div>
                <div class="pure-controls" style="text-align: right">
                    <button type="submit" class="button-success pure-button button-large pure-u-3-3">
                        保存
                    </button>
                </div>
            </fieldset>
        </form>
    </div>
</div>
{% endblock %}
{% block scripts %}
    <script src="{{ url_for('static', filename='layer-v3.5.1/layer.js') }}"></script>
<script>
    function checkPost(){
        let name = jQuery("#name").val()
        let password = jQuery("#password").val()
        let desc = jQuery("#desc").val()
        if(name.length < 3){
            layer.msg("名称不能小于3个字符")
            return false
        }
        if(password.length < 6 || password.length> 16){
            layer.msg("密码长度应该在6和16之间")
            return false
        }
        if(desc.length < 8 || password.length> 32){
            layer.msg("简介长度应该在6和16之间")
            return false
        }
        return true
    }
        function showBox(club_id){
            console.log(club_id)
            let request_html = jQuery("#access-box").html()
            let re = new RegExp("to-be-replace","g"); //定义正则表达式
            let ret = new RegExp("form-old","g"); //定义正则表达式
            let rete = new RegExp("mod-go-access","g"); //定义正则表达式
            //第一个参数是要替换掉的内容，第二个参数"g"表示替换全部（global）。
            let NewStr = request_html.replace(re, club_id.toString()); //第一个参数是正则表达式。
            let newString = NewStr.replace(ret, "form"); //第一个参数是正则表达式。
            let new_string = newString.replace(rete, "go-access"); //第一个参数是正则表达式。
            console.log(new_string)
            layer.open({
              type: 1, title: '输入访问密码',
              skin: 'layui-layer-demo', //样式类名
              closeBtn: 1, //不显示关闭按钮
              anim: 2,
              shadeClose: true, //开启遮罩关闭
              content: new_string
            });
        }
        jQuery("#go-access").on("click", function (){
            console.log($('#form').serialize())
            $.ajax({
            type: "post",   //请求类型
            dataType: "json",   //请求数据返回类型
            url: "/admin/json_data/sent_data",    //请求地址
            data: $('#form').serialize(),       //表单序列化
            success: function (result) {        //成功
                console.log(result);
                if (result.code === 200) {
                    console.log(result);
                    console.log("成功");
                    {#$("#club_id").text(result.data.name);#}
                    {#$("#password").text(result.data.phone);#}
                } else {
                    console.log(result);
                    console.log("失败");
                }
            },
            error: function (result) {      //失败
                console.log(result);
                console.log("异常");
            }
        });
        return false;
        })
    </script>
{% endblock %}